x86/mm: introduce a p2m class
authorEd White <edmund.h.white@intel.com>
Tue, 3 Feb 2015 10:27:46 +0000 (11:27 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 3 Feb 2015 10:27:46 +0000 (11:27 +0100)
Use the class to differentiate between host and nested p2m's, and
potentially other classes in the future.

Fix p2m class checks that implicitly assume nested and host are
the only two classes that will ever exist.

Signed-off-by: Ed White <edmund.h.white@intel.com>
Acked-by: Tim Deegan <tim@xen.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/mm/guest_walk.c
xen/arch/x86/mm/hap/guest_walk.c
xen/arch/x86/mm/p2m-ept.c
xen/arch/x86/mm/p2m.c
xen/include/asm-x86/p2m.h

index fd2314e3302ca3a3ce1a087db19796f716cc8409..9e26342fc0a7c130e87cbc74fea7e1be54e392da 100644 (file)
@@ -2914,7 +2914,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
     /* Mem sharing: unshare the page and try again */
     if ( npfec.write_access && (p2mt == p2m_ram_shared) )
     {
-        ASSERT(!p2m_is_nestedp2m(p2m));
+        ASSERT(p2m_is_hostp2m(p2m));
         sharing_enomem = 
             (mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0);
         rc = 1;
index 1b26175a881825d221bf7da3c77a75b980337cde..d8f5a356ca8703ef88d97e8b1793cead1b1c2327 100644 (file)
@@ -99,7 +99,7 @@ void *map_domain_gfn(struct p2m_domain *p2m, gfn_t gfn, mfn_t *mfn,
                                  q);
     if ( p2m_is_paging(*p2mt) )
     {
-        ASSERT(!p2m_is_nestedp2m(p2m));
+        ASSERT(p2m_is_hostp2m(p2m));
         if ( page )
             put_page(page);
         p2m_mem_paging_populate(p2m->domain, gfn_x(gfn));
index 25d9792d075bdf0e8a50f484b9b63f67c3808c3f..381a1966e695f02d5b538f4033722ca0d8de8296 100644 (file)
@@ -64,7 +64,7 @@ unsigned long hap_p2m_ga_to_gfn(GUEST_PAGING_LEVELS)(
                                      &p2mt, NULL, P2M_ALLOC | P2M_UNSHARE);
     if ( p2m_is_paging(p2mt) )
     {
-        ASSERT(!p2m_is_nestedp2m(p2m));
+        ASSERT(p2m_is_hostp2m(p2m));
         pfec[0] = PFEC_page_paged;
         if ( top_page )
             put_page(top_page);
@@ -106,7 +106,7 @@ unsigned long hap_p2m_ga_to_gfn(GUEST_PAGING_LEVELS)(
             put_page(page);
         if ( p2m_is_paging(p2mt) )
         {
-            ASSERT(!p2m_is_nestedp2m(p2m));
+            ASSERT(p2m_is_hostp2m(p2m));
             pfec[0] = PFEC_page_paged;
             p2m_mem_paging_populate(p2m->domain, gfn_x(gfn));
             return INVALID_GFN;
index e21a92db2ec611be963e9a03c6ad7cbeabec50b2..c2d7720d15040579d0b7880b33c5a16f726e249c 100644 (file)
@@ -769,8 +769,8 @@ out:
     if ( needs_sync != sync_off )
         ept_sync_domain(p2m);
 
-    /* For non-nested p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && !p2m_is_nestedp2m(p2m) && need_iommu(d) &&
+    /* For host p2m, may need to change VT-d page table.*/
+    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
index c1b75456582ec568402aff6f780f4c4b57d332fe..6a06e9fe8d368216f7b9195439aaf0eed72e0319 100644 (file)
@@ -71,6 +71,7 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)
 
     p2m->domain = d;
     p2m->default_access = p2m_access_rwx;
+    p2m->p2m_class = p2m_host;
 
     p2m->np2m_base = P2M_BASE_EADDR;
 
@@ -158,6 +159,7 @@ static int p2m_init_nestedp2m(struct domain *d)
             p2m_teardown_nestedp2m(d);
             return -ENOMEM;
         }
+        p2m->p2m_class = p2m_nested;
         p2m->write_p2m_entry = nestedp2m_write_p2m_entry;
         list_add(&p2m->np2m_list, &p2m_get_hostp2m(d)->np2m_list);
     }
@@ -202,7 +204,7 @@ int p2m_init(struct domain *d)
 int p2m_is_logdirty_range(struct p2m_domain *p2m, unsigned long start,
                           unsigned long end)
 {
-    ASSERT(!p2m_is_nestedp2m(p2m));
+    ASSERT(p2m_is_hostp2m(p2m));
     if ( p2m->global_logdirty ||
          rangeset_contains_range(p2m->logdirty_ranges, start, end) )
         return 1;
@@ -263,7 +265,7 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn,
 
     if ( (q & P2M_UNSHARE) && p2m_is_shared(*t) )
     {
-        ASSERT(!p2m_is_nestedp2m(p2m));
+        ASSERT(p2m_is_hostp2m(p2m));
         /* Try to unshare. If we fail, communicate ENOMEM without
          * sleeping. */
         if ( mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0 )
@@ -431,7 +433,7 @@ int p2m_alloc_table(struct p2m_domain *p2m)
 
     p2m_lock(p2m);
 
-    if ( !p2m_is_nestedp2m(p2m)
+    if ( p2m_is_hostp2m(p2m)
          && !page_list_empty(&d->page_list) )
     {
         P2M_ERROR("dom %d already has memory allocated\n", d->domain_id);
@@ -1710,7 +1712,7 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* "Host" p2m tables can have shared entries &c that need a bit more 
      * care when discarding them */
-    ASSERT(p2m_is_nestedp2m(p2m));
+    ASSERT(!p2m_is_hostp2m(p2m));
     /* Nested p2m's do not do pod, hence the asserts (and no pod lock)*/
     ASSERT(page_list_empty(&p2m->pod.super));
     ASSERT(page_list_empty(&p2m->pod.single));
index e86e26f9c18691527990a5b8f360844801416f8e..e93c55150562f2d52b303e1f8c4058b2f558fb03 100644 (file)
@@ -172,6 +172,11 @@ typedef unsigned int p2m_query_t;
                              (P2M_RAM_TYPES | P2M_GRANT_TYPES |  \
                               p2m_to_mask(p2m_map_foreign)))
 
+typedef enum {
+    p2m_host,
+    p2m_nested,
+} p2m_class_t;
+
 /* Per-p2m-table state */
 struct p2m_domain {
     /* Lock that protects updates to the p2m */
@@ -188,6 +193,8 @@ struct p2m_domain {
 
     struct domain     *domain;   /* back pointer to domain */
 
+    p2m_class_t       p2m_class; /* host/nested/? */
+
     /* Nested p2ms only: nested p2m base value that this p2m shadows.
      * This can be cleared to P2M_BASE_EADDR under the per-p2m lock but
      * needs both the per-p2m lock and the per-domain nestedp2m lock
@@ -297,7 +304,15 @@ struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base);
  */
 struct p2m_domain *p2m_get_p2m(struct vcpu *v);
 
-#define p2m_is_nestedp2m(p2m)   ((p2m) != p2m_get_hostp2m((p2m->domain)))
+static inline bool_t p2m_is_hostp2m(const struct p2m_domain *p2m)
+{
+    return p2m->p2m_class == p2m_host;
+}
+
+static inline bool_t p2m_is_nestedp2m(const struct p2m_domain *p2m)
+{
+    return p2m->p2m_class == p2m_nested;
+}
 
 #define p2m_get_pagetable(p2m)  ((p2m)->phys_table)